(()=>{function r(){let j=document.currentScript;if(!j)throw Error("[Rootabl] No script tag found");let Q=(new URL(j.src,window.location.href).searchParams.get("business")||j.dataset.business||j.dataset.brand||"").trim().toLowerCase();if(!Q)throw Error("[Rootabl] No business attribute found");return{business:Q,email:j.dataset.email?.trim()??""}}var h=Reflect.get(EventTarget.prototype,"addEventListener"),I=Reflect.get(EventTarget.prototype,"removeEventListener"),[H0,B0]=M0();function X(j,J,Q,$){(j===window?H0:h).call(j,J,Q,$)}function E(j,J,Q,$){(j===window?B0:I).call(j,J,Q,$)}function M0(){try{let j=()=>{return};return h.call(window,"rootabl-listener-probe",j),I.call(window,"rootabl-listener-probe",j),[h,I]}catch{return[window.addEventListener,window.removeEventListener]}}var F=Set,t=Map;function A(j){return`${document.location.hostname==="localhost"?"http://localhost:3002":"https://myrootabl.com"}/${j}`}var U0=5,g=new F;function H(j,J,Q=""){try{let $=J instanceof Error?J.message:String(J),Z=J instanceof Error?J.stack??"":"",x=`${j}:${$}`;if(g.has(x))return;if(g.size>=U0)return;g.add(x),fetch(A("script-error"),{method:"POST",headers:{"Content-Type":"application/json"},keepalive:!0,body:JSON.stringify({bid:Q||window.rootabl?.business||"unknown",url:window.location.href,context:j,message:$.slice(0,1000),stack:Z.slice(0,4000)})}).catch(()=>{return})}catch{}}function Y(...j){let J=location.hostname.includes("localhost");try{J||=Boolean(localStorage.getItem("_rlogger"))}catch{}if(!J)return;console.debug("%cRootabl","background-color:teal;color:white;padding:2px 4px;border-radius:2px",...j)}var D0=100,V0=10,O0=history.replaceState.bind(history),c=!1,e;function j0(j){c=!0;try{O0(history.state,"",j)}finally{c=!1}e?.()}function J0(j){if(window.navigation){let x=window.navigation;X(x,"currententrychange",(W)=>{if(c)return;let K=W;if(!K.navigationType)return;if(K.from.url===x.currentEntry?.url)return;j()});return}let J=history.pushState.bind(history),Q=history.replaceState.bind(history),$=window.location.href;e=()=>{$=window.location.href};let Z=()=>{if(window.location.href===$)return;$=window.location.href,j()};history.pushState=(...x)=>{let q=J(...x);return Z(),q},history.replaceState=(...x)=>{let q=Q(...x);return Z(),q},X(window,"popstate",Z)}function Q0(j,J){let Q=new F,$,Z=new WeakSet,x=()=>{let G=[...Q];Q=new F,$=void 0;for(let z of G)K(z);if(G.length)j(G)},q=new MutationObserver((G)=>{for(let z of G)for(let D of z.addedNodes)if(D.nodeType===Node.ELEMENT_NODE)Q.add(D);if(Q.size&&!$)$=setTimeout(x,D0)});function W(G,z=0){if(z>=V0||Z.has(G))return;Z.add(G);try{q.observe(G,{childList:!0,subtree:!0}),J?.(G)}catch(D){Y("Failed to observe shadow root",D)}for(let D of G.querySelectorAll("*"))if(D.shadowRoot)W(D.shadowRoot,z+1)}function K(G){if(G.shadowRoot)W(G.shadowRoot);for(let z of G.querySelectorAll("*"))if(z.shadowRoot)W(z.shadowRoot)}let T=document.documentElement;if(!T)return()=>{return};return q.observe(T,{childList:!0,subtree:!0}),K(T),W}function P(j,J){let Q=Date.now(),$=1000,Z,x=!1,q=()=>{if(x||j())return;if(Date.now()-Q>=300000){J?.();return}Z=setTimeout(q,$),$=Math.min($*2,50000)};return q(),()=>{if(x=!0,Z)clearTimeout(Z)}}var P0=/^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,63}$/,_=/[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,63}/g,N0=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Z0=["undefined","null","test"],b0=[/example\.(com|org|net)$/i,/test\.(com|org|net)$/i,/sample\.(com|org|net)$/i,/email\.(com|org|net)$/i,/placeholder/i,/your-?email/i,/@example$/i];function $0(j){return typeof j==="string"&&P0.test(j)&&!b0.some((J)=>J.test(j))}function B(j){return typeof j==="string"&&N0.test(j)}function p(...j){return j.find(B)??""}function y(j){let J=j?.toLowerCase().trim()??"";return Z0.includes(J)?"":J}function k(j){let J=j??"";if(Z0.includes(J))return"";return J.toLowerCase().replaceAll(" ","")}var y0=["email","email_address","invitee_email","email-address-lead"],u=['input[type="email"]','input[name*="email" i]','input[id*="email" i]','input[placeholder*="email" i]','input[autocomplete="email"]'].join(","),C0=new F(["SCRIPT","STYLE","NOSCRIPT","SVG","CANVAS","VIDEO","AUDIO","IFRAME","OBJECT","EMBED","INPUT","TEXTAREA"]),L0=20,T0=10,A0=1000,v=100,d={scanned:1,typed:2,submitted:3},_0=['button[type="submit"]',"button:not([type])",'input[type="submit"]'].join(",");class l{scriptEmail;business;inputDelayMs;inputTimeouts=new F;inputTimers=new WeakMap;pendingInputs=new F;stopDiscovery;onSubmit;listenedRoots=new WeakSet;onShadowRootSeen;constructor(j="",J="",Q=A0){this.scriptEmail=j;this.business=J;this.inputDelayMs=Q}scanPage(){let j=[this.scriptEmail];try{let J=new URLSearchParams(window.location.search);for(let Q of y0)j.push(J.get(Q))}catch(J){Y("Failed to read email URL parameters",J)}j.push(window.M?.currentUser?.attributes?.email),j.push(window.Shopify?.checkout?.email),j.push(window.order_summary?.customer?.email);for(let J of["ajs_user_traits","ajs_user_traits_v2"])try{let Q=JSON.parse(localStorage.getItem(J)??"{}");j.push(Q.email)}catch(Q){Y("Failed to read email traits",{key:J,error:Q})}for(let J of f(document,this.onShadowRootSeen))if(J.type!=="password")j.push(J.value);for(let J of document.querySelectorAll(".welcome-customer"))j.push(J.textContent?.match(_)?.[0]);return M(j)}scanElements(j){let J=[];for(let Q of j)R(Q,J,0,this.onShadowRootSeen);return M(J)}start(j){let J=(x)=>this.captureInput(x0(x),j),Q=(x)=>{let q=window.HubSpotFormsV4?.getFormFromEvent(x)?.getFormFieldValues()?.map((K)=>K.value),W=M(q??[]);if(W.length)j(W,"submitted")};this.onSubmit=(x)=>{this.captureSubmission(R0(x),j)};let $=(x)=>{if(x.key!=="Enter")return;let q=x0(x);if(!(q instanceof HTMLInputElement)||q.type==="password")return;if(q.matches(u))this.captureSubmission(q,j,[q.value]);else if(f(m(q)??q).length)this.captureSubmission(q,j)},Z=(x)=>{let q=k0(x,_0);if(!q)return;if(q.getAttribute("type")==="submit"||m(q))this.captureSubmission(q,j)};X(document,"input",J,{capture:!0}),X(document,"submit",this.onSubmit,{capture:!0}),X(document,"keydown",$,{capture:!0}),X(document,"click",Z,{capture:!0}),X(window,"hs-form-event:on-submission:success",Q)}listenToShadowRoot(j){if(!this.onSubmit||this.listenedRoots.has(j))return;this.listenedRoots.add(j),X(j,"submit",this.onSubmit,{capture:!0})}captureSubmission(j,J,Q=[]){let $=[...Q],Z=j?m(j):null;if(Z){for(let q of f(Z))if(q.type!=="password")$.push(q.value)}let x=M($);if(x.length)J(x,"submitted")}captureInput(j,J){if(!(j instanceof HTMLInputElement)&&!(j instanceof HTMLTextAreaElement))return;if(j instanceof HTMLInputElement&&j.type==="password")return;let Q=this.inputTimers.get(j);if(Q)clearTimeout(Q),this.inputTimeouts.delete(Q);let $=setTimeout(()=>{this.inputTimeouts.delete($),this.pendingInputs.delete(j);let Z=M([j.value]);if(Z.length)J(Z,"typed")},this.inputDelayMs);this.inputTimers.set(j,$),this.inputTimeouts.add($),this.pendingInputs.add(j)}flushPendingInputs(){let j=[];for(let J of this.pendingInputs)j.push(J.value);return this.clearPendingInputTimers(),M(j)}clearPendingInputTimers(){for(let j of this.inputTimeouts)clearTimeout(j);this.inputTimeouts.clear(),this.inputTimers=new WeakMap,this.pendingInputs.clear()}discover(j){this.stopDiscovery?.();let J=M([this.scriptEmail])[0];this.stopDiscovery=P(()=>{try{let Q=this.scanPage().filter(($)=>$!==J);if(Q.length)return j(Q),!0}catch(Q){Y("Email discovery failed",Q),H("email-discovery",Q,this.business)}return!1})}stop(){this.stopDiscovery?.(),this.clearPendingInputTimers()}}function M(j){let J=new F;for(let Q of j){if(typeof Q!=="string")continue;let $=Q.trim().toLowerCase();if($0($)){if(J.add($),J.size>=v)break}}return[...J]}function R(j,J,Q,$){if(Q>L0)return;if(j.nodeType===Node.TEXT_NODE){for(let x of j.textContent?.match(_)??[])J.push(x);return}if(j.nodeType===Node.DOCUMENT_FRAGMENT_NODE){for(let x of j.childNodes)R(x,J,Q+1,$);return}if(j.nodeType!==Node.ELEMENT_NODE)return;let Z=j;if(Z.matches(u)){let x=Z;if(x.type!=="password")J.push(x.value)}if(C0.has(Z.tagName))return;if(Z.tagName==="A")for(let x of Z.getAttribute("href")?.match(_)??[])J.push(x);if(Z.shadowRoot)$?.(Z.shadowRoot),R(Z.shadowRoot,J,Q+1,$);for(let x of j.childNodes)R(x,J,Q+1,$)}function f(j,J,Q=0){let $=[];for(let Z of j.querySelectorAll("*")){if(Z.matches(u))$.push(Z);if(!Z.shadowRoot||Q>=T0)continue;J?.(Z.shadowRoot),$.push(...f(Z.shadowRoot,J,Q+1))}return $}function k0(j,J){for(let Q of j.composedPath())if(Q instanceof Element&&Q.matches(J))return Q;return null}function R0(j){for(let J of j.composedPath())if(J instanceof Element)return J;return j.target instanceof Element?j.target:null}function x0(j){for(let J of j.composedPath())if(J instanceof HTMLInputElement||J instanceof HTMLTextAreaElement)return J;return j.target instanceof HTMLInputElement||j.target instanceof HTMLTextAreaElement?j.target:null}function m(j){let J=j;while(J){let Q=J.closest("form");if(Q)return Q;let $=J.getRootNode();J=$ instanceof ShadowRoot?$.host:null}return null}var f0=new F(["co.uk","org.uk","gov.uk","ac.uk","com.au","net.au","org.au","co.nz","org.nz","co.za","com.br","co.jp","co.kr","com.mx","com.cn","co.in","com.sg"]),N={getItem:(j)=>window.localStorage.getItem(j),setItem:(j,J)=>window.localStorage.setItem(j,J)},C={getItem:(j)=>window.sessionStorage.getItem(j),setItem:(j,J)=>window.sessionStorage.setItem(j,J)};function U(j,J){try{return j.getItem(J)??""}catch{return""}}function V(j,J,Q){try{return j.setItem(J,Q),!0}catch{return!1}}function L(j){try{let J=`${encodeURIComponent(j)}=`;for(let Q of document.cookie.split(";")){let $=Q.trim();if($.startsWith(J))return decodeURIComponent($.slice(J.length))}}catch{}return""}function O(j,J,Q=31536000){let $=location.protocol==="https:",Z=w(location.hostname)??location.hostname,x=new Date(Date.now()+Q*1000).toUTCString(),q=[`${encodeURIComponent(j)}=${encodeURIComponent(J)}`,`expires=${x}`,"path=/",`samesite=${$?"None":"Lax"}`,`domain=${Z}`];if($)q.push("secure");document.cookie=q.join("; ")}function w(j){if(j==="localhost"||/^[0-9.]+$/.test(j))return;let J=j.split(".");if(J.length<2)return;let Q=J.slice(-2).join(".");return f0.has(Q)&&J.length>=3?`.${J.slice(-3).join(".")}`:`.${Q}`}var q0="_rootabl_iframe_reload_count",w0=2;class n{options;receivedParentParams=!1;constructor(j){this.options=j}start(){X(window,"message",this.onMessage),this.processAll(),this.announceReadyToParent()}processAll(){document.querySelectorAll("iframe").forEach((j)=>this.process(j))}processAdded(j){for(let J of j){if(J instanceof HTMLIFrameElement)this.process(J);J.querySelectorAll("iframe").forEach((Q)=>this.process(Q))}}process(j){try{let J=this.options.getVisitId(),Q=this.options.getReferral(),$=J||(Q?`ref-${Q}`:"");if(j.src.includes("https://calendly.com/")){let Z=new URL(j.src),x=`rootabl[${$}]`,q=Z.searchParams.get("utm_term")??"";if(!q.includes(x))Z.searchParams.set("utm_term",q?`${q}+${x}`:x),j.src=Z.href}if(j.src.includes("https://form.typeform.com/")){let Z=new URL(j.src),x=new URLSearchParams(Z.hash.replace(/^#/,""));if(x.set("rootabl",$),Z.hash=x.toString(),Z.searchParams.set("rootabl",$),j.src!==Z.href)j.src=Z.href}this.sendParams(j.contentWindow)}catch(J){Y("Failed to process iframe",J)}}onMessage=(j)=>{if(!j.data||typeof j.data!=="object")return;if(j.data.type==="rootabl-ready"){this.sendParamsToReadyChild(j);return}if(j.data.type!=="rootabl-params")return;if(window.parent===window||j.source!==window.parent)return;if(j.data.bid!==this.options.business)return;this.receivedParentParams=!0;let J=y(typeof j.data.rootabl==="string"?j.data.rootabl:""),Q=B(j.data.vid)?j.data.vid:"",$=this.options.getVisitId();if(this.options.onParentParams(J,Q),!Q){this.syncUrlReferral();return}let Z=this.options.getVisitId();if(Z!==Q||Z===$&&$){this.syncUrlReferral();return}let x=new URL(window.location.href);if(x.searchParams.get("_rvid")===Z){this.syncUrlReferral();return}let q=Number.parseInt(U(C,q0)||"0",10);if(q>=w0){Y("Max iframe reloads reached; skipping URL sync",{count:q});return}V(C,q0,String(q+1)),x.searchParams.set("_rvid",Z);let W=this.options.getReferral();if(W)x.searchParams.set("rootabl",W);else x.searchParams.delete("rootabl");window.location.replace(x.href)};syncUrlReferral(){let j=new URL(window.location.href),J=j.searchParams.get("rootabl");if(J===null)return;let Q=this.options.getReferral();if(k(J)===Q)return;if(Q)j.searchParams.set("rootabl",Q);else j.searchParams.delete("rootabl");j0(j.href)}announceReadyToParent(){if(window.parent===window)return;P(()=>{if(this.receivedParentParams)return!0;try{window.parent.postMessage({type:"rootabl-ready"},"*")}catch(j){Y("Failed to announce iframe readiness",j)}return!1})}sendParamsToReadyChild(j){if(!j.source)return;if([...document.querySelectorAll("iframe")].some((Q)=>Q.contentWindow===j.source))this.sendParams(j.source)}sendParams(j){if(!j)return;try{j.postMessage({type:"rootabl-params",bid:this.options.business,rootabl:this.options.getReferral(),vid:this.options.getVisitId()},"*")}catch(J){Y("Failed to send tracking params to child frame",J)}}}var Y0=["click","auxclick","contextmenu"],X0=["pointerdown","keydown"],S0=3000,h0=['a[href^="https://buy.stripe.com"]',"stripe-pricing-table","stripe-buy-button"],I0=["stripe.com","chargebee.com","paypal.com","klarna.com","affirm.com","afterpay.com","paddle.com","lemonsqueezy.com","instagram.com","facebook.com","threads.net","tiktok.com","youtube.com","x.com","twitter.com","linkedin.com","pinterest.com","reddit.com","tumblr.com","snapchat.com","discord.com","discord.gg","whatsapp.com","wa.me","telegram.org","t.me","slack.com","wikipedia.org","google.com","bing.com","yahoo.com","duckduckgo.com","baidu.com","yandex.com","github.com","gitlab.com","bitbucket.org","apple.com","microsoftonline.com","okta.com"],E0=["divineflowcommunity.co","protrusive.app","village.myhomeschoolvillage.com"],g0=[".pdf",".zip",".csv",".txt",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".rtf",".mp3",".mp4",".mov",".avi",".webm",".jpg",".jpeg",".png",".gif",".webp",".svg"];class s{activeVisitId="";activeReferral="";listeningForLinks=!1;stripeDiscoveries=new F;stopStripeDiscoveries=new F;linkRestorations=new WeakMap;apply(j,J=""){if(!j)return;this.activeVisitId=j,this.activeReferral=J,this.listenForLinkActivations(),this.decorateStripe(),this.decorateChargebee(j)}stop(){if(this.listeningForLinks){this.listeningForLinks=!1;for(let j of X0)E(window,j,this.predecorateActivatedLink,!0);for(let j of Y0)E(window,j,this.decorateActivatedLink,!0)}for(let j of this.stopStripeDiscoveries)j();this.stopStripeDiscoveries.clear(),this.stripeDiscoveries.clear()}listenForLinkActivations(){if(this.listeningForLinks)return;this.listeningForLinks=!0;for(let j of X0)X(window,j,this.predecorateActivatedLink,!0);for(let j of Y0)X(window,j,this.decorateActivatedLink,!0)}predecorateActivatedLink=(j)=>{if(j.type==="keydown"&&j.key!=="Enter")return;this.decorateActivatedLink(j)};decorateActivatedLink=(j)=>{let J=p0(j);if(!J)return;let Q=this.linkRestorations.get(J);if(Q&&J.href!==Q.decoratedHref)clearTimeout(Q.timer),this.linkRestorations.delete(J),Q=void 0;let $=Q?.originalHref??J.getAttribute("href");if(!$)return;try{let Z=new URL(J.href);if(!m0(J,Z)||u0(Z.hostname))return;let q=c0(Z,this.activeVisitId,this.activeReferral)&&Z.href!==J.href;if(!q&&!Q)return;if(q)J.href=Z.href,Y("Applied cross-domain tracking",Z.href);if(Q)clearTimeout(Q.timer);let W=J.href,K=setTimeout(()=>{if(this.linkRestorations.get(J)?.timer!==K)return;if(this.linkRestorations.delete(J),J.href===W)J.setAttribute("href",$)},S0);this.linkRestorations.set(J,{originalHref:$,decoratedHref:W,timer:K})}catch{Y("Failed to process link",J.href)}};decorateStripe(){for(let j of h0)if(this.decorateStripeSelector(j))this.stripeDiscoveries.delete(j);else this.startStripeDiscovery(j)}startStripeDiscovery(j){if(this.stripeDiscoveries.has(j))return;this.stripeDiscoveries.add(j);let J=()=>{return},Q=()=>{this.stripeDiscoveries.delete(j),this.stopStripeDiscoveries.delete(J)};if(J=P(()=>{if(!this.stripeDiscoveries.has(j))return Q(),!0;if(!this.decorateStripeSelector(j))return!1;return Q(),!0},Q),this.stripeDiscoveries.has(j))this.stopStripeDiscoveries.add(J)}decorateStripeSelector(j){let J=document.querySelectorAll(j);if(!J.length)return!1;let Q=j.startsWith("a[href");for(let $ of J)if(Q)try{let Z=$,x=new URL(Z.href);if(x.searchParams.get("client_reference_id")!==this.activeVisitId)x.searchParams.set("client_reference_id",this.activeVisitId),Z.href=x.href}catch{Y("Failed to process Stripe link")}else if($.getAttribute("client-reference-id")!==this.activeVisitId)$.setAttribute("client-reference-id",this.activeVisitId);return!0}decorateChargebee(j){window.Chargebee?.getInstance?.().getCart?.()?.setCustomer?.({cf_rootabl_referral:j})}}function c0(j,J,Q=""){if(j.hostname.includes("savvycal.com"))return j.searchParams.set("metadata[rootabl]",J),!0;if(j.hostname.includes("typeform.com")){if(j.hash.includes(`rootabl=${J}`))return!1;let Z=new URLSearchParams(j.hash.replace(/^#/,""));return Z.set("rootabl",J),j.hash=Z.toString(),!0}if(j.searchParams.set("_rvid",J),(j.hostname.includes(".mn.co")||E0.includes(j.hostname))&&Q&&!j.searchParams.has("rootabl"))j.searchParams.set("rootabl",Q);return!0}function p0(j){return j.composedPath().find((J)=>J instanceof HTMLAnchorElement&&J.hasAttribute("href"))}function m0(j,J){if(j.hasAttribute("download")||j.hasAttribute("data-rootabl-ignore"))return!1;if(!["http:","https:"].includes(J.protocol))return!1;return!g0.some((Q)=>J.pathname.toLowerCase().endsWith(Q))}function u0(j,J=window.location.hostname){let Q=j.toLowerCase().replace(/\.$/,""),$=J.toLowerCase().replace(/\.$/,"");if(w(Q)===w($))return!0;let Z=`.${Q}.`;return I0.some((x)=>Z.includes(`.${x}.`))}function F0(){let j=new Uint8Array(16);window.crypto.getRandomValues(j);let J=BigInt(Date.now()),Q=new DataView(j.buffer);return Q.setUint16(0,Number(J/2n**32n),!1),Q.setUint32(2,Number(J%2n**32n),!1),j[6]=j[6]&15|112,j[8]=j[8]&63|128,[j.slice(0,4),j.slice(4,6),j.slice(6,8),j.slice(8,10),j.slice(10,16)].map(($)=>Array.from($,(Z)=>Z.toString(16).padStart(2,"0")).join("")).join("-")}var W0="_rpv";class i{storage;createdIds=new F;current;constructor(j=C){this.storage=j}resolve(j,J=window.location.href){if(this.current?.url===J&&(!this.current.visitId||this.current.visitId===j))return this.current={...this.current,visitId:j||this.current.visitId},this.write(this.current),this.current;let Q=this.read(),$=Q?.pending===!0&&this.createdIds.has(Q.id);if(Q?.url===J&&(!Q.pending||$)&&(!Q.vid||Q.vid===j)){let Z={id:Q.id,url:J,visitId:j||Q.vid,pending:Q.pending};return this.write(Z),this.current=Z,Z}return this.create(j,J)}reconcile(j,J,Q){if(Q&&j.pending||!j.visitId||j.visitId===J){let $={...j,visitId:J,pending:Q?!1:j.pending};return this.write($),this.current=$,$}return this.create(J,j.url)}rotateAfterFailure(j,J){if(!j.pending)return j;return this.create(J,j.url)}create(j,J){let Q={id:F0(),url:J,visitId:j,pending:!0};return this.createdIds.add(Q.id),this.current=Q,this.write(Q),Q}read(){let j=U(this.storage,W0);if(!j)return null;try{let J=JSON.parse(j);if(!B(J.id)||typeof J.url!=="string"||!J.url)return null;return{id:J.id,url:J.url,vid:B(J.vid)?J.vid:"",pending:J.pending===!0}}catch{return null}}write(j){V(this.storage,W0,JSON.stringify({id:j.id,url:j.url,vid:j.visitId,pending:j.pending}))}}class o{options;activeSend;sendRequested=!1;lastDeliveredSignature="";constructor(j){this.options=j}send(){return this.sendRequested=!0,this.activeSend??=this.drain().finally(()=>{this.activeSend=void 0}),this.activeSend}sendBeacon(){let{payload:j}=this.options.snapshot(),J=G0(j),Q=JSON.stringify(J);if(Q===this.lastDeliveredSignature)return;if(navigator.sendBeacon){if(navigator.sendBeacon(this.options.endpoint,new Blob([Q],{type:"application/json"})))this.lastDeliveredSignature=Q;return}(this.options.request??fetch)(this.options.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:Q,keepalive:!0}).catch(()=>{return})}async drain(){while(this.sendRequested)this.sendRequested=!1,await this.deliver()}async deliver(){let j;try{j=this.options.snapshot();let J=G0(j.payload),Q=JSON.stringify(J),$;try{$=await(this.options.request??fetch)(this.options.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},keepalive:!0,body:Q})}catch(x){this.options.onFailure(j.pageView),Y("Error sending analytics",x);return}if(!$.ok){this.options.onFailure(j.pageView);return}let Z;try{Z=await $.json()}catch(x){if(!d0(x))throw x;this.options.onFailure(j.pageView),Y("Error reading analytics response",x);return}this.options.onSuccess(Z,j.pageView),this.lastDeliveredSignature=Q}catch(J){if(j)this.options.onFailure(j.pageView);Y("Error sending analytics",J),H("transport",J)}}}function G0(j){return Object.fromEntries(Object.entries(j).filter(([,J])=>J!==""&&J!==null&&J!==void 0&&!(Array.isArray(J)&&J.length===0)))}var v0=new F(["Failed to fetch","Load failed","NetworkError when attempting to fetch resource."]);function d0(j){return j instanceof TypeError&&v0.has(j.message)}var b=new URL(window.location.href),l0=3,K0=86400,n0=3600,s0=63072000;class a{business;pageview={id:"",url:""};uid="";visit_id="";link_id="";ref="";emails=new t;rutm="";pageViews=new i;pageViewState;links=new s;emailCapture;frames;transport;pageViewRotationResends=0;cookieTtl;constructor(j,J={}){this.business=j;if(this.emailCapture=new l(J.scriptEmail,this.business),i0(b)){Y("Tracking is disabled on this Rootabl app page");return}this.uid=p(L("_ruid"),U(N,"_ruid")),this.visit_id=p(b.searchParams.get("_rvid")??"",L("_rvid"),U(N,"_rvid")),this.setPageView(this.pageViews.resolve(this.visit_id)),this.cookieTtl=z0(U(N,"_rttl")),this.ref=this.resolveReferral(),this.link_id=b.searchParams.get("lid")??"",this.rutm=b.searchParams.get("rutm")??"",this.frames=new n({business:this.business,getVisitId:()=>this.visit_id,getReferral:()=>this.ref,onParentParams:(Z,x)=>this.adoptParentParams(Z,x)}),this.transport=new o({endpoint:A("collect"),snapshot:()=>({payload:this.getPayload(),pageView:this.pageViewState}),onSuccess:(Z,x)=>this.acceptCollectionResponse(Z,x),onFailure:(Z)=>this.rotateFailedPageView(Z)}),this.frames.start(),this.emailCapture.start((Z,x)=>{if(this.addEmails(Z,x))this.send()}),J0(()=>{try{this.handleNavigation()}catch(Z){Y("Failed to handle navigation",Z),H("navigation",Z,this.business)}});let Q=Q0((Z)=>{try{this.handleAddedElements(Z)}catch(x){Y("Failed to handle added elements",x),H("added-elements",x,this.business)}},(Z)=>this.emailCapture.listenToShadowRoot(Z));this.emailCapture.onShadowRootSeen=Q,this.refreshIntegrations();let $=this.addEmails(this.emailCapture.scanPage(),"scanned");if(!window.frameElement||$)this.send();this.emailCapture.discover((Z)=>{if(this.addEmails(Z,"scanned"))this.send()}),X(window,"pagehide",()=>{this.addEmails(this.emailCapture.flushPendingInputs(),"typed"),this.sendBeacon()})}addEmails(j,J){let Q=!1;for(let $ of M(j)){let Z=this.emails.get($);if(Z===void 0&&this.emails.size>=v)continue;if(Z===void 0||d[J]>d[Z])this.emails.set($,J),Q=!0}return Q}send(){return this.transport?.send()??Promise.resolve()}sendBeacon(){this.transport?.sendBeacon()}updateTrackingData(j,J,Q=!1,$=this.pageViewState){if(j&&j!==this.uid)this.uid=j,S("_ruid",j,this.cookieTtl);if(J&&J!==this.visit_id)this.visit_id=J,S("_rvid",J,this.cookieTtl),O("rootabl",J,this.cookieTtl),this.refreshIntegrations();if(!J||!$||$!==this.pageViewState)return;let Z=$.id;if(this.setPageView(this.pageViews.reconcile($,J,Q)),this.pageview.id===Z)this.pageViewRotationResends=0;else if(this.pageViewRotationResends({email:j,source:J})),uid:this.uid,vid:this.visit_id}}acceptCollectionResponse(j,J){if(j.test)return;this.acceptCookieTtl(j.ttl);let Q=B(j.uid)?j.uid:"",$=B(j.vid)?j.vid:"";if(Q||$)this.updateTrackingData(Q,$,!0,J)}acceptCookieTtl(j){let J=z0(j);if(!J||J===this.cookieTtl)return;if(this.cookieTtl=J,V(N,"_rttl",String(J)),this.uid)S("_ruid",this.uid,J);if(this.visit_id)S("_rvid",this.visit_id,J),O("rootabl",this.visit_id,J);if(this.ref)O("rootabl.ref",this.ref,J)}rotateFailedPageView(j){if(!j.pending||this.pageViewState?.id!==j.id)return;this.setPageView(this.pageViews.rotateAfterFailure(j,this.visit_id||j.visitId))}handleNavigation(){this.setPageView(this.pageViews.resolve(this.visit_id)),this.refreshIntegrations(),this.addEmails(this.emailCapture.scanPage(),"scanned"),this.send()}handleAddedElements(j){let J=this.emailCapture.scanElements(j);if(J.length&&this.addEmails(J,"scanned"))this.send();this.links.apply(this.visit_id,this.ref),this.frames?.processAdded(j)}refreshIntegrations(){this.links.apply(this.visit_id,this.ref),this.frames?.processAll()}adoptParentParams(j,J){let Q=y(j),$=Q!==this.ref;if($)this.ref=Q,O("rootabl.ref",Q,this.cookieTtl??K0);let Z=Boolean(J)&&J!==this.visit_id;if(J)this.updateTrackingData("",J);if(!$)return;if(!Z)this.refreshIntegrations();this.send()}setPageView(j){this.pageViewState=j,this.pageview={id:j.id,url:j.url}}resolveReferral(){let j=k(b.searchParams.get("rootabl"));if(j){if(L("rootabl.ref")!==j)O("rootabl.ref",j,this.cookieTtl??K0);return j}return y(L("rootabl.ref"))}}function S(j,J,Q){O(j,J,Q),V(N,j,J)}function z0(j){let J=typeof j==="number"?j:Number(j||"");if(!Number.isFinite(J)||J<=0)return;return Math.min(Math.max(Math.round(J),n0),s0)}function i0(j){return j.hostname.includes("app.rootabl.com")&&!j.pathname.includes("/login")&&!j.pathname.includes("/signup")}try{let j=r(),J=()=>{try{window.rootabl??=new a(j.business,{scriptEmail:j.email})}catch(Q){console.error("[Rootabl] Failed to initialize:",Q),H("init",Q,j.business)}};if(document.readyState==="loading")X(window,"DOMContentLoaded",J,{once:!0});else J()}catch(j){console.error("[Rootabl] Failed to initialize:",j)}})();